package com.kstech.ks_gaz01.data

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.kstech.ks_gaz01.R
import com.kstech.ks_gaz01.databinding.LayoutItemReadfileBinding

class ReadFileAdapter : BaseQuickAdapter<String, ReadFileAdapter.VH>() {
    private var clickPosition = -1

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: LayoutItemReadfileBinding = LayoutItemReadfileBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): VH {
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: String?) {
        holder.binding.fileName.text = item
        if (position == clickPosition) {
            holder.binding.root.setBackgroundColor(
                ContextCompat.getColor(
                    context,
                    R.color.background_titleRv_selected
                )
            )
        } else {
            holder.binding.root.setBackgroundColor(
                ContextCompat.getColor(
                    context,
                    R.color.background_body
                )
            )
        }
    }




    fun clickPosition(position: Int) {
        this.clickPosition = position
    }
}